#!/bin/env python
#-*- coding:utf-8 -*-

#----------------------------------------------------------------------------
# Name     :      GUI.py
# Purpose  :      Mysql tool for ucweb, and this is the py file of gui.
# Author   :      Albert cheng
# Created  :      2012-10-29
# Copyright:     (c) 2012 by Albertcheng
# Licence  :      wxWindows license
#----------------------------------------------------------------------------

import wx
import string,re
from request_handler import request_sqlite
import wx.lib.delayedresult as dr
from base_panel import basePanel as bp

class tianjie_panel(bp):

    def __init__(self, parent = None, log = None):
        bp.__init__(self, parent, log)
        self.nb = parent
        self.log = log


        
        self.cfg_path = r"./xml/tianjie/"
         
        self.prop_file = self.cfg_path+"prop.xml"
        self.skill_file = self.cfg_path+"attackskills.xml"
        self.equip_file = self.cfg_path+"equipment.xml"
        #--------------------------
        
        self.player_detail_ui_label = [
                                    ["UC账号".decode('utf-8'),"PlayerID","角色名".decode('utf-8'),"等级".decode('utf-8'),"经验值".decode('utf-8')],
                                    ["最近登陆时间".decode('utf-8'), "活力值".decode('utf-8'),"敏捷属性".decode('utf-8'),"力量属性".decode('utf-8')],
                                    ]
                
        self.player_detail_ui_label[1].append("智力属性".decode('utf-8'))
            
        self.player_detail_ui_label.append(["功勋值".decode('utf-8'),"元宝".decode('utf-8'),"职业".decode('utf-8')])
        self.player_detail_ui_value_tag = [
                                    "k_player.ucId","k_player.id","k_player.name","k_player.level","k_player.exp",
                                    "k_player.lastLoginTime","k_player.energy,k_player.maxEnergy","k_player_fightmsg.agility","k_player_fightmsg.strength","k_player_fightmsg.intellect",
                                    "k_player.exploit","k_player.money","k_player_fightmsg.role",
                                    "k_player_prop_effect.LAttackCount","k_player_prop_effect.LDefenseCount","k_player_prop_effect.LExpCount","k_player_prop_effect.LHpCount",
                                    "k_player_prop_effect.attackCount","k_player_prop_effect.defenseCount","k_player_prop_effect.expCount","k_player_prop_effect.hpCount",
                                    ]
            #--------------------------
        self.player_detail_ui_label.append(["攻击灵药".decode('utf-8'),"防御灵药".decode('utf-8'),"经验灵药".decode('utf-8'),"生命灵药".decode('utf-8')])
        self.player_detail_ui_label.append(["攻击圣药".decode('utf-8'),"防御圣药".decode('utf-8'),"经验圣药".decode('utf-8'),"生命圣药".decode('utf-8')])
                      
        self.base_sizer_manager()
        self.evt_manager()
        self.run_bg_mysql_thread("tianjie")
        
    def evt_manager(self):
        self.tianjie_search_v.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN,lambda e: self.tianjie_search_v.SetValue(''))
        self.tianjie_search_v.Bind(wx.EVT_TEXT_ENTER, self.OnSearch)
        
        
        


    def base_sizer_manager(self):
        
        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
        
        search_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.search_t = wx.StaticText(self,-1,"查询您的UCID或者角色昵称：".decode('utf-8'))
        self.tianjie_search_v = wx.SearchCtrl(self,-1, size=(500,25),style=wx.TE_PROCESS_ENTER)
        self.tianjie_search_v.ShowCancelButton(True)
        
        search_sizer.Add(self.search_t,0,wx.LEFT|wx.BOTTOM|wx.ALL,5)
        search_sizer.Add(self.tianjie_search_v,0,wx.LEFT|wx.ALL,5)
        
        self.main_sizer.Add(search_sizer,0,wx.LEFT|wx.ALL,5)
        self.main_sizer.Add(wx.StaticLine(self,-1,size=(1500,1)),0,wx.LEFT|wx.ALL,5)
        
        self.sizer_manager()
        self.SetSizer(self.main_sizer)
        self.main_sizer.Fit(self.nb)
        
    def sizer_manager(self):
        tj_sizer = wx.BoxSizer(wx.VERTICAL)
        
        role_sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.player_detail_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, label="角色基础数据".decode('utf-8')), wx.VERTICAL)
        self.player_detail_ui = self.make_ui_code(self.player_detail_ui_label,self.player_detail_sizer)
        
        
        tj_sizer.Add(self.player_detail_sizer,0, wx.EXPAND, 5)
        tj_sizer.Add(role_sizer,0, wx.EXPAND, 5)
        self.main_sizer.Add(tj_sizer)
        

    

                
    def tianjie_refresh_gui(self,dr):
        try:
            self.proj = self.proj_def[int(self.nb.GetSelection())]
        except:
            wx.MessageBox("项目数据初始化错误，无法查询".decode("utf-8"),"Error",wx.OK)
            return
        if self.proj == "config":
            setattr(self.nb,"ssdz_refresh_mysql_flag",False)
            setattr(self.nb,"tianjie_refresh_mysql_flag",False)
            return
        if getattr(self.nb,"tianjie_refresh_mysql_flag"):
            self.Log.log("refreshing gui for proj [%s]" % self.proj )
            if self.player == {}:
                return
            self.refresh_data_player_detail_ui()
            
